<?php

class newsComponents extends sfComponents
{
    public function executeCulture()
    {
        $returnUrl = $this->getModuleName() . '/' . $this->getActionName();
        if( ($id = (int)$this->getRequestParameter('id', 0)) )
        {
            $returnUrl .= '?id=' . $id;
        }
        // TODO: move to system module
        $this->setFlash('returnUrl',$returnUrl);
    }

    public function executePhoto()
    {
        // To check how many photos still available for upload
        $this->allowPhoto = false;
        $allowedPhotos = News::allowableNumberPhotos();

        // Select photos for news
        $this->photos = Files::getByObj(MyConstants::TYPE_NEWS, $this->getRequestParameter('id'), get_user_id());

        // Assumes that we have no photos
        $this->allowPhoto = true;
        if( $this->photos )
        {
              $this->allowPhoto = count($this->photos) < $allowedPhotos;
        }
    }
    public function executeSeo()
    {
    	$c = new Criteria();
    	$c->add(SeoPeer::OBJ_TYPE, 'news');
    	$c->add(SeoPeer::OBJ_ID, $this->news->getId());
    	$c->add(SeoPeer::OBJ_ACTION, 'view');
    	$c->add(SeoPeer::CULTURE, get_culture());
    	$this->seoObj = SeoPeer::doSelectOne($c);
    	$this->setFlash('seoReturnUrl', 'news/edit?id=' . $this->news->getId());
    }

}
